#include "pch.hpp"
#include "PositionComponent.hpp"
#include "Components.hpp"

using namespace Engine;
using namespace Engine::Entity;




PositionComponent* PositionComponent::create()
{
	return new PositionComponent();
}
///////////////////////////////////////////////////////////////////////////////////////////////////

PositionComponent::PositionComponent()
	: Component(false)
{}
///////////////////////////////////////////////////////////////////////////////////////////////////

PositionComponent::~PositionComponent()
{}
///////////////////////////////////////////////////////////////////////////////////////////////////




Component::ID PositionComponent::id() const
{
	return Components::Position;
}
///////////////////////////////////////////////////////////////////////////////////////////////////




void PositionComponent::setPosition(float3 position)
{
	m_transform._41 = position.x;
	m_transform._42 = position.y;
	m_transform._43 = position.z;
}
///////////////////////////////////////////////////////////////////////////////////////////////////

void PositionComponent::setRotation(float3x3 rotation)
{
	m_transform = float4x4(rotation, position());
}
///////////////////////////////////////////////////////////////////////////////////////////////////




float3 PositionComponent::position() const
{
	return m_transform.row4().xyz();
}
///////////////////////////////////////////////////////////////////////////////////////////////////

float3x3 PositionComponent::rotation() const
{
	return m_transform.rotation();
}
///////////////////////////////////////////////////////////////////////////////////////////////////




void PositionComponent::registerType(Script::System::ptr engine)
{
	engine->registerObjectType("PositionComponent", 0, asOBJ_REF);
	engine->registerObjectBehaviour("PositionComponent", asBEHAVE_FACTORY, "PositionComponent@ f()", asFUNCTION(&create), asCALL_CDECL);
	engine->registerObjectBehaviour("PositionComponent", asBEHAVE_ADDREF, "void f()", asMETHOD(Script::Object, AddRef), asCALL_THISCALL);
	engine->registerObjectBehaviour("PositionComponent", asBEHAVE_RELEASE, "void f()", asMETHOD(Script::Object, Release), asCALL_THISCALL);

	engine->registerObjectBehaviour("PositionComponent", asBEHAVE_IMPLICIT_REF_CAST, "Component@ f()", asFUNCTION((&refCast<PositionComponent, Component>)), asCALL_CDECL_OBJLAST);
	engine->registerObjectBehaviour("Component", asBEHAVE_REF_CAST, "PositionComponent@ f()", asFUNCTION((&refCast<Component, PositionComponent>)), asCALL_CDECL_OBJLAST);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
